home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / DOCSCAN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  2.3 KB  |  94 lines

  1. /*  docscan.c - scan indexed documents */
  2. #include   "stdio.h"
  3. #include   "ctype.h"
  4. #include   "cminor.h"
  5. #include   "document.h"
  6. #include   "btree.h"
  7. #include   "bt_macro.h"
  8.  
  9. int  compf() ;
  10. int  sizef() ;
  11. #define RW_MODE  2                      /* read & write allowed */
  12. #define BOF_REL  0                      /* seek relative to Begin.-of-file */
  13.  
  14. main(argc,argv)
  15.   int   argc ;
  16.   char  *argv[] ;
  17.   {
  18.      int   ret , datfile , line ;
  19.      char  fn[65] ;
  20.      RECPOS   fs  ;
  21.      IX_DESC  ixd ;
  22.      DOCUMENT doc ;
  23.      ENTRY e, e2  ;
  24.  
  25.      if( argc < 2 )
  26.         {  printf(" USAGE:  docindex   doc-file-name \n") ;
  27.            exit(5) ;
  28.         }
  29.  
  30.      add_str(fn,argv[1],".idx") ;
  31.      if( openix(fn,&ixd,compf,sizef) < 0 )
  32.         {  printf(" can't open the index file \n") ;
  33.            exit(11) ;
  34.         }
  35.  
  36.      add_str(fn,argv[1],".dat") ;
  37.      datfile = gopen(fn,RW_MODE,BIN_MODE) ;
  38.      if( datfile < 0 )
  39.         {  printf(" can't open the data file \n") ;
  40.            closeix(&ixd) ;
  41.            exit(12) ;
  42.         }
  43.  
  44.      scan_input(e.key) ;
  45.      ret = find_ix(&e,&ixd) ;
  46.      get_current(&e2,&ixd) ;            /* find out where we are */
  47.      line = 0 ;
  48.      while( cmp_part(e.key,e2.key) == 0 )
  49.         {  lseek(datfile,e2.rptr,BOF_REL) ;     /* retrieve the data */
  50.            read(datfile,&doc,sizeof(DOCUMENT) ) ;
  51.            if( line >= 20 )
  52.               {  printf("\n press a key for more \n") ;
  53.                  getkey() ;
  54.                  line = 0 ;
  55.               }
  56.            display_doc(&doc) ;
  57.            line = line + 5 ;
  58.            if( get_next(&e2,&ixd) == EOIX )
  59.               break ;
  60.         }
  61.      closeix(&ixd) ;
  62.   }
  63.  
  64.  
  65. int  scan_input(s)
  66.   char  s[] ;
  67.   {
  68.      char ans[81] ;
  69.  
  70.      printf(" which field to scan ? \n") ;
  71.      printf(" a = Addressee / d = Date / s = Subject :") ;
  72.      getstr(ans,80) ;
  73.      s[0] = toupper(ans[0]) ;
  74.      s[1] = '*' ;
  75.      s[2] = '\0' ;
  76.  
  77.      printf(" value to look for: ") ;
  78.      getstr(ans,ADR_LEN-1) ;
  79.      strcat(s,ans) ;
  80.   }
  81.  
  82. int  display_doc(pdoc)                  /* display one document record */
  83.   DOCUMENT *pdoc ;
  84.   {
  85.      printf("\n document file name: %s \n",pdoc->dname) ;
  86.      printf(" addressed to: %s \n",pdoc->addressee) ;
  87.      printf(" date sent: %s \n",pdoc->date) ;
  88.      printf(" subject: %s \n",pdoc->subject) ;
  89.   }
  90.  
  91.  
  92.  
  93.  
  94.